var ModuleUtil = {
  getDepAndWorkShop: function (hasAll) {
    return new Promise(function (resole, reject) {
      ajaxRequest('equipment/getDepartmentDropdown').then(function (res) {
        var deps = [];
        if (hasAll) {
          deps.push({
            value: '',
            label: '全部',
          });
        }
        for (var dep of res) {
          var depObj = {
            value: dep.departmentCode,
            label: dep.deptName,
            workshops: []
          };
          if (hasAll) {
            depObj.workshops.push({
              value: '',
              label: '全部',
            });
          }
          for (var workshop of dep.workshops) {
            depObj.workshops.push({
              value: workshop.id,
              label: workshop.workshopName
            });
          }
          deps.push(depObj);
        }
        resole(deps);
      }).catch(function (error) {
        resole([]);
      });
    });
  },

  getMachineStatus: function (status) {
    if (status === undefined) {
      return '';
    }

    var statusList = ['警报', '待机', '运行', '离线'];
    status = statusList[status];
    if (status === undefined) {
      return '';
    }
    return status;
  },

  getFileImgSize: function (file) {
    return new Promise(function (resole) {
      var reader = new FileReader();
      reader.onload = function (e) {
        var data = e.target.result;
        var image = new Image();
        image.onload = function () {
          var width = image.width;
          var height = image.height;
          resole({
            width: width,
            height: height
          });
        };
        image.src = data;
      };
      reader.readAsDataURL(file);
    });
  }
};
